package com.insigma.business.qrcode.soldier.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;


public class ThreadPoolManager {
    private static ExecutorService executorService;

    private static ScheduledExecutorService  scheduler ;

    private static Integer threadNum = 30;

    private static Integer schedulerThreadNum = 10;

    public static ExecutorService getInstance(){
        if (executorService == null) {
            synchronized (ThreadPoolManager.class) {
                if (executorService == null) {
                    executorService = Executors.newFixedThreadPool(threadNum);
                }
            }
        }
        return executorService;
    }

    public static ScheduledExecutorService getScheduledThreadPoolInstance(){
        if (scheduler == null) {
            synchronized (ThreadPoolManager.class) {
                if (scheduler == null) {
                    scheduler = Executors.newScheduledThreadPool(schedulerThreadNum);
                }
            }
        }
        return scheduler;
    }
}
